import { readdirSync } from 'fs'
import { join, resolve } from 'path'
import Router from 'koa-router'

const router = new Router()

const dirPath = join(__dirname, 'controllers')
const controllers = readdirSync(dirPath)

controllers.forEach(controller => {
  const module = require(join(dirPath, controller))
  const p = controller.replace('.js', '')

  router.use(`/${p}`, module.routes(), module.allowedMethods())
})

export default router
